|
Hi,
I have a country master.I want to display code and name of the country in a gridview using csharp.
I have an add new button,if i click on that button a new empty row should get added to the gridview,where i can enter a new country details.Like that if a i click on that button for required number of times,that many rows should get added.
I should insert into the table(SQL server2005) on click of an update button at one shot.
Someone please help me out to achieve this application.....
waiting for a positive reply..
|
|
|
|
|
public void EmptyGrid()
{
DataTable TempTable = new DataTable();
TempTable.Columns.Add("sino");
TempTable.Columns.Add("name");
TempTable.Columns.Add("gender");
TempTable.Columns.Add("qualification");
TempTable.PrimaryKey = new DataColumn[] { TempTable.Columns["sino"] };
TempTable = BindEmptyRows(3, TempTable);
GridView1.DataSource = TempTable;
GridView1.DataBind();
}
//Method to Bind Rows
private DataTable BindEmptyRows(int nofoRows, DataTable dt)
{
for (int i = 0; i < nofoRows; i++)
{
DataRow dr = dt.NewRow();
dr["sino"] = dt.Rows.Count + 1;
dr["name"] = string.Empty;
dr["gender"] = "0";
dr["qualification"] = "0";
dt.Rows.Add(dr);
}
return dt;
}
//refer :Temporary Values in Grid[^]">
Padmanabhan
|
|
|
|
|
Hi,thanx for imm. reply.
This is fine if rows are fixed...
I want dynamic number of rows to be added on click of a button outside the gridview....
iam a beginner in .net..
|
|
|
|
|
Hi,on click of a button iam able to add a new row....i tried and i used the logic given by you...
Thanx a lot..
|
|
|
|
|
//these two methods will create 3 rows in page load
public void EmptyGrid()
{
DataTable TempTable = new DataTable();
TempTable.Columns.Add("sino");
TempTable.Columns.Add("name");
TempTable.Columns.Add("gender");
TempTable.Columns.Add("qualification");
TempTable.PrimaryKey = new DataColumn[] { TempTable.Columns["sino"] };
TempTable = BindEmptyRows(3, TempTable);
GridView1.DataSource = TempTable;
GridView1.DataBind();
}
//Method to Bind Rows
private DataTable BindEmptyRows(int nofoRows, DataTable dt)
{
for (int i = 0; i < nofoRows; i++)
{
DataRow dr = dt.NewRow();
dr["sino"] = dt.Rows.Count + 1;
dr["name"] = string.Empty;
dr["gender"] = "0";
dr["qualification"] = "0";
dt.Rows.Add(dr);
}
return dt;
}
//when u click a button outside the grid then
protected void btnNew_Click(object sender, EventArgs e)
{
SaveGridDataInTempTable();
DataTable dtNew = Temp.Copy();
BindEmptyRows(1, dtNew);
Temp = dtNew;
GridView1.DataSource = dtNew;
GridView1.DataBind();
}
//each and every click it will create a new row
Padmanabhan
|
|
|
|
|
Hi,
In my application i have java script method to open a new window, when i click a button new window is opening , but before opening new window i want to make fire postback to server from the Parent page, how can i do this plz let me give reply...
function window()
{
window.open("secondpage.aspx","_blank","width=475px,height=100px");
}
am calling this method like OnClientClick="return Window() in the source page.
|
|
|
|
|
Since window is a javascript keyword, change your function name window() to something like openWindow
function openWindow()
{
document.forms[0].submit();
window.open("secondpage.aspx","_blank","width=475px,height=100px");
}
|
|
|
|
|
Hi,
Let me clearly explain my problem,
This is my java script function to open new window,
function openWindow()
{
document.forms[0].submit();
var sUrl = "aspxSecond.aspx";
var sFeatures = "width=475px,height=100px,left=350px,top=400px,location=no,";
window.open(sUrl,"_blank",sFeatures);
}
I am calling the method like,
<asp:button id="btn" runat="server" onclientclick="return openWindow();" text="Export">
And i write the server side code for the btn click,
Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click
session("val")=1
End sub
In the second page i should get the session value as soon as i need to clear the session value...so every click i need to pass the session value.
BUT The PROBLEM is the btn_click is not firing for second time click ...
if any clarification plz let me ask..
Regards,
|
|
|
|
|
Don't worry about it!
if you wanna go back from the current page to your parent page!
you can write like this:
function openWindow(){
var handle=window.open("url");//this is a new window.
//if you wanna close the new window,you can write:
handle.close();
//if you wanna go to the parent window,you can write:
document.parent.window.location.href="parent url";
}
|
|
|
|
|
I have a griview in my page with paging. The gridview contains the first column as UserId which is a Datakey column. The issue is when I go to secondpage, it is giving the error saying that " Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" .
On the second page, the index getting is 10. What am I doing wrong here? How should i get the datakey value? Following is the code I'm using.
int Userid = 0;
int index = 0;
foreach (GridViewRow gvr in SearchGrid.Rows)
{
CheckBox cb = (CheckBox)gvr.FindControl("chkbox1");
if (cb.Checked)
{
index = gvr.DataItemIndex;
Userid = Convert.ToInt32(SearchGrid.DataKeys[index].Value);
}
}
I am getting error on the last line when clicked on 2nd page. Can anybody provide any solution?
Thanks in advance.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
//if u r using only one datakey, then use like this
Userid = Convert.ToInt32(SearchGrid.DataKeys[index][0].Value);
Padmanabhan
|
|
|
|
|
I think this cannot be done. Because everytime I will ge the value at Index 0.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
DataKeys[index][0] in this index points ur row index and [0] points ur no.of datakeys u have...
if u give 2 datakeys named as sino and id
sino= Convert.ToInt32(SearchGrid.DataKeys[index][0].Value); //gives sino
id= Convert.ToInt32(SearchGrid.DataKeys[index][1].Value); //gives id
(or)
sino= Convert.ToInt32(SearchGrid.DataKeys[index]["sino"].Value); //sino
id= Convert.ToInt32(SearchGrid.DataKeys[index]["id"].Value); //gives id
Padmanabhan
|
|
|
|
|
oh.. Thank you very much. the information is pretty clear. thanks
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
You are looping through GridViewRows collection, therefore use GridViewRow.RowIndex property to get the index of the row in the for loop. Also change your code like this
index = gvr.RowIndex;
Userid = Convert.ToInt32(SearchGrid.DataKeys[index].Value);
|
|
|
|
|
Hello,
Visual Studio 2005
Default.ASPX
Two TextBoxes>>1.TextBox1 (To enter Start Roll Number)
2.TextBox2 (To enter End Roll Number)
Response.Redirect("Secm1998.aspx?startrol=" & TextBox1.Text & "&endrol=" & TextBox2.Text)
Secm1998.aspx>>1.CrystalReportSource1 2.CrystalReportViewer1
Secm1998.rpt
I wish to show only those records whose roll number (Oracle 10G Table) in the range of TextBox1 and TextBox2 in the CrystalReportViewer1.
For this:
How do i set CrystalReportViewer1.SelectionFormula as Rol (name of column in the table) in range of TextBox1 and TextBox2
Thanks & Regards
Girish Sharma
|
|
|
|
|
Set the formula like this
"{Student.Rol} >= " + rollNumber1 + " AND ({Student.Rol } <= " + rollNumber2
Here rollNumber1 and rollNumber2 are values of TextBox1 and TextBox2 respectively
|
|
|
|
|
Thanks for your reply and it worked fine; but one little question further:
Dim mySelectFormula As String = "ToNumber({secm98.rol}) >= " & Request.QueryString("startrol") & " AND ToNumber({secm98.rol}) <= " & Request.QueryString("endrol")
CrystalReportViewer1.SelectionFormula = mySelectFormula
Now it is asking username and password before showing the report; how do i set the username and password in the code.
Regards
Girish Sharma
|
|
|
|
|
In ASP.net how we show messagebox and alerts ti users when an error occurs????
|
|
|
|
|
Use javascript
OR
u Can use
Response.Write("alert('Enter the message here');") in the code window.
But when u use Ajax controls Response.Write not possible
u can use label and write the msg in that label
modified on Thursday, May 21, 2009 12:56 AM
|
|
|
|
|
use java script or show the messages in validation summary (in Vlaidation summary there is a property called ShowMessageBox="True")
Padmanabhan
|
|
|
|
|
Alternatively you can display a javascript alert after a postback by
Page.ClientScript.RegisterStartupScript(this.GetType(), "testkey", " window.alert('Your Alert Message')");
|
|
|
|
|
I use ASP.NET + C#
In My form I have a Gridview inside gridview i use a dropdown list
In dropdownlist it contain --Select-- and other items
I want to add a validation to this dropdownlist so that the user must choose an item other than --Select--
I need to validate using javascript .How can i do that
|
|
|
|
|
//if u have given selectedindex for your dropdownlist --select-- as 0
function error()
{
if ( document.getElementById('..._dropdownlist').selectedIndex = "0")
alert('select atleast one');
}
//but it will more easy if u provide a required field validator.
Padmanabhan
|
|
|
|
|
i will not work bcs i place the dropdownlist inside the gridview .
|
|
|
|